package src.view;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;


import src.controller.MainMenuController;
import src.resource.PublicResource;


public class MainMenu extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//private Image im;
	private JMenu jMenuSystem,jMenuUser,jMenuPostOffice,jMenuMailBox;
	private JMenuItem jMenuItemExit,jMenuItemAddUser,jMenuItemManageUsers,jMenuItemAddPostOffice,jMenuItemManagePostOffices,jMenuItemManageTrustRelationships,jMenuItemAddMailBox,jMenuItemManageMailBox;
	private JMenuBar menuBar;
	//private JToolBar toolBar = new JToolBar();
	   // addButtons(toolBar);
	private JPanel jPanelCenter;
	private Container panel;
	private MainMenuController controller;
	private static MainMenu instance=null;
	private final String  PATH=PublicResource.getPath();
	
	public static MainMenu getInstance(MainMenuController controller){
		if(instance==null)
			instance=new MainMenu(controller);
		return instance;
	}

	private MainMenu(MainMenuController controller) {
		
		super("InTouch");
		this.controller=controller;
		this.init();
		
		
		this.jMenuItemExit.addActionListener(new ActionExitHandler());
		this.jMenuItemAddUser.addActionListener(new ActionShowAddUser());
		this.jMenuItemManageUsers.addActionListener(new ActionShowManageUsers());
		this.jMenuItemAddPostOffice.addActionListener(new ActionShowAddPostOffice());
		this.jMenuItemManagePostOffices.addActionListener(new ActionShowManagePostOffices());
		this.jMenuItemManageTrustRelationships.addActionListener(new ActionShowManageTrustRelationships());
		this.jMenuItemAddMailBox.addActionListener(new ActionShowAddMailBox());
		this.jMenuItemManageMailBox.addActionListener(new ActionShowManageMailBoes());

		
	}
	
	private void init(){
		
		
		this.jMenuSystem = new JMenu("System");
		this.jMenuSystem.setIcon(new ImageIcon(PATH+"gnome-session-properties.png"));
		this.jMenuSystem.setMnemonic('S');
		
		
		
		this.jMenuItemExit = new JMenuItem("Exit");
		this.jMenuItemExit.setMnemonic('x');
		this.jMenuItemExit.setIcon(new ImageIcon(PATH+"application-exit.png"));
		
		this.jMenuUser = new JMenu("User");
		this.jMenuUser.setIcon(new ImageIcon(PATH+"system-users.png"));
		this.jMenuUser.setMnemonic('U');
		
		this.jMenuPostOffice=new JMenu("Post Office");
		this.jMenuPostOffice.setMnemonic('P');
		this.jMenuPostOffice.setIcon(new ImageIcon(PATH+"drawer.png"));
		
		this.jMenuMailBox=new JMenu("MailBox");
		this.jMenuMailBox.setMnemonic('B');
		this.jMenuMailBox.setIcon(new ImageIcon(PATH+"mail-mark-read.png"));
		
		this.jMenuItemAddPostOffice = new JMenuItem("Add Post Office");
		this.jMenuItemAddPostOffice.setMnemonic('O');
		this.jMenuItemAddPostOffice.setIcon(new ImageIcon(PATH+"drawerAdd.png"));
		
		this.jMenuItemManagePostOffices=new JMenuItem("Manage Post Offices");
		this.jMenuItemManagePostOffices.setMnemonic('a');
		this.jMenuItemManagePostOffices.setIcon(new ImageIcon(PATH+"file-roller.png"));

		this.jMenuItemManageTrustRelationships=new JMenuItem("Manage Trust Relationships");
		this.jMenuItemManageTrustRelationships.setMnemonic('T');
		this.jMenuItemManageTrustRelationships.setIcon(new ImageIcon(PATH+"application-pgp.png"));
		
		this.jMenuItemManageUsers=new JMenuItem("Manage users");
		this.jMenuItemManageUsers.setMnemonic('M');
		this.jMenuItemManageUsers.setIcon(new ImageIcon(PATH+"users-icon.png"));

		
		this.jMenuItemAddUser = new JMenuItem("Add users");
		this.jMenuItemAddUser.setMnemonic('A');
		this.jMenuItemAddUser.setIcon(new ImageIcon(PATH+"contact-new.png"));
		
		this.jMenuItemManageUsers=new JMenuItem("Manage users");
		this.jMenuItemManageUsers.setMnemonic('M');
		this.jMenuItemManageUsers.setIcon(new ImageIcon(PATH+"users-icon.png"));
		
		this.jMenuItemAddMailBox=new JMenuItem("Add MailBoxes");
		this.jMenuItemAddMailBox.setMnemonic('i');
		this.jMenuItemAddMailBox.setIcon(new ImageIcon(PATH+"mail-message-new.png"));
		
		this.jMenuItemManageMailBox=new JMenuItem("Manage MailBoxes");
		this.jMenuItemManageMailBox.setMnemonic('l');
		this.jMenuItemManageMailBox.setIcon(new ImageIcon(PATH+"mail-inbox.png"));
		
		this.jMenuMailBox.add(this.jMenuItemAddMailBox);
		this.jMenuMailBox.add(this.jMenuItemManageMailBox);

		
		this.jMenuUser.add(this.jMenuItemAddUser);
		this.jMenuUser.add(this.jMenuItemManageUsers);
		
		this.jMenuPostOffice.add(this.jMenuItemAddPostOffice);
		this.jMenuPostOffice.add(this.jMenuItemManagePostOffices);
		this.jMenuPostOffice.add(this.jMenuItemManageTrustRelationships);
		
		this.jMenuSystem.add(this.jMenuItemExit);

		this.menuBar = new JMenuBar();
		this.setJMenuBar(this.menuBar);
		this.menuBar.add(this.jMenuSystem);
		this.menuBar.add(this.jMenuUser);
		this.menuBar.add(this.jMenuPostOffice);
		this.menuBar.add(this.jMenuMailBox);
		this.jPanelCenter=new JPanel();
		
		
		
		//this.btnSalir=new JButton("Salir",new ImageIcon("system-log-out1.png"));
		
		//this.toolBar=new JToolBar();
		//this.toolBar.addSeparator
		//this.toolBar.add(this.btnNuevo);
		//this.toolBar.addSeparator();
		//this.toolBar.add(this.btnSalir);
		//this.toolBar.setFloatable(false);
		

		panel = getContentPane();
		panel.setLayout(new BorderLayout());
		//panel.add(this.toolBar,BorderLayout.NORTH);
		//panel.add(this.tablero.getJpaPanel(),BorderLayout.CENTER);()
		//panel.add(this.jPanelCenter,BorderLayout.CENTER);
		//panel.add(AddUser.getInstance(new AddUserController(new System())),BorderLayout.CENTER);
		//this.jMenuItemAddUser.addActionListener(this.accionNuevo);
		//this.jMenuItemExit.addActionListener(this.accionSalir);
		//this.btnNuevo.addActionListener(this.accionNuevo);
		//this.btnSalir.addActionListener(this.accionSalir);
		
		this.setSize(800, 768);
		this.setVisible(true);
		
		//this.im = Toolkit.getDefaultToolkit().getImage("15.png");
		//this.setIconImage(im);
		
		

	}

	public Container getPanel() {
		return panel;
	}

	public void setPanel(Container panel) {
		this.panel = panel;
	}

	public JPanel getJPanelCenter() {
		return jPanelCenter;
	}

	public void setJPanelCenter(JPanel jPanelCenter) {
		this.jPanelCenter = jPanelCenter;
	}
	
	private class ActionExitHandler implements ActionListener {
		public void actionPerformed(ActionEvent e) {

			dispose();

		}
	}
	
	private class ActionShowAddUser implements ActionListener {
		public void actionPerformed(ActionEvent e) {

			controller.performShowAddUser();

		}
	}
	
	private class ActionShowManageUsers implements ActionListener {
		public void actionPerformed(ActionEvent e) {

			controller.performShowManageUsers();

		}
	}
	
	private class ActionShowAddPostOffice implements ActionListener {
		public void actionPerformed(ActionEvent e) {

			controller.performShowAddPostOffice();

		}
	}
	
	private class ActionShowManagePostOffices implements ActionListener {
		public void actionPerformed(ActionEvent e) {

			controller.performShowManagePostOffices();

		}
	}
	
	private class ActionShowManageTrustRelationships implements ActionListener {
		public void actionPerformed(ActionEvent e) {

			controller.performShowManageTrustRelationships();

		}
	}
	
	private class ActionShowAddMailBox implements ActionListener {
		public void actionPerformed(ActionEvent e) {

			controller.performShowAddMailBox();

		}
	}
	
	private class ActionShowManageMailBoes implements ActionListener {
		public void actionPerformed(ActionEvent e) {

			controller.performShowManageMailBox();

		}
	}

	
	}

